<template>
    <div id="author-set">
        <div>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>创作设置</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <el-card class="box-card">
            <el-form ref="form" :model="form" label-width="160px">
                <el-form-item label="作者认证是否开启审核">
                    <el-switch v-model="form.apply_review" active-value="1"
                               inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="创建作品是否开启审核">
                    <el-switch  v-model="form.anime_review" active-value="1"
                               inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="发布文章是否开启审核">
                    <el-switch  v-model="form.chapter_review" active-value="1"
                               inactive-value="0"></el-switch>
                </el-form-item>
                <el-form-item label="打赏金额">
                    <el-select
                            v-model="form.reward_package"
                            multiple
                            filterable
                            allow-create
                            default-first-option
                            placeholder="打赏金额"
                            :class="this.$store.state.windowWidth<=this.$store.state.MaxWidth?'maxWidth':'minWidth'">
                        <el-option
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="">
                    <el-button type="primary" size="small" @click="submit">保存</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</template>

<script>
  export default {
    name: "author-set",
    data() {
      return {
        form: {
          apply_review: '',
          anime_review: '',
          chapter_review: '',
          reward_package:'',
        },
        options: [],
      }
    },
    created() {
      this.getData();
    },
    methods: {
      getData() {
        this.$axios.post('admin/writer/get_config').then((res) => {
          this.form = res.data;
          if (this.form.reward_package == '') {
            this.form.reward_package = [];
          } else {
            this.form.reward_package = this.form.reward_package.split(",")
          }
        });
      },
      submit(){
        this.form.reward_package = this.form.reward_package.join(',');
        this.$axios.post('admin/writer/set_config', {config: this.form}).then((res) => {
          this.$message.success('成功');
          this.getData();
        });
      },
    }
  }
</script>

<style scoped>

</style>